//
//  YCTitleContentView.m
//  DemoTitleContent
//
//  Created by tangkexiong on 15/9/2.
//  Copyright (c) 2015年 tangkexiong. All rights reserved.
//

#import "YCTitleContentView.h"

#define kReuseCell @"cellTitle"
#define kTitleViewCellWidth 100
#define kTitleViewHeight 49
#define kDuration 0.3
#define kSelectedViewHeight 2

#pragma mark - YCTitleContentView

@interface YCTitleContentView()<UICollectionViewDataSource, UICollectionViewDelegateFlowLayout, UIGestureRecognizerDelegate> {
    UICollectionView *_titleView;   ///< 标签栏控件
    UIView *_selectedView;          ///< 选中效果指示控件
    UIView *_contentView;           ///< 内容区域控件
    
    UIViewController *_curContentVC;    ///< 当前的视图控制器
    UIViewController *_lastContentVC;   ///< 当前的视图控制器的前一个
    UIViewController *_nextContentVC;   ///< 当前的视图控制器的下一个
    
    UIPanGestureRecognizer *_panGesture;    ///< 滑动手势
    
    NSLayoutConstraint *_constraintTitleViewHeight;     ///< 标签栏的高度约束
    
    NSInteger _tempNum;
    CGFloat _tempTitleViewHeight;
    CGFloat _tempTitleViewCellWidth;
    CGFloat _tempSelectViewHeight;
    
    BOOL _isPaning;
}

@property (nonatomic, assign) UIViewController *viewController; ///< 所在的视图控制器

@end

@implementation YCTitleContentView

#pragma mark - UIView

- (instancetype)init {
    self = [super init];
    
    if (self) {
        [self _initConfig];
    }
    
    return self;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    
    [self _initConfig];
}

- (void)willMoveToSuperview:(UIView *)newSuperview {
    [super willMoveToSuperview:newSuperview];
    
    if (newSuperview) {
        [self _buildTitleView];
        [self _buildContentView];
    }
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    if (_isPaning) {
        
    } else {
        [self _updateView];
    }
    
}

#pragma mark - Update View

- (void)_initConfig {
    _selectedView = nil;
    _tempNum = 0;
    _tempSelectViewHeight = kSelectedViewHeight;
    _tempTitleViewHeight = kTitleViewHeight;
    _tempTitleViewCellWidth = kTitleViewCellWidth;
    
    _panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(_handlePanGesture:)];
    _panGesture.delegate = self;
}

- (void)_buildTitleView {
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    flowLayout.minimumInteritemSpacing = 0;
    [flowLayout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
    _titleView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, _tempTitleViewHeight) collectionViewLayout:flowLayout];
    _titleView.showsHorizontalScrollIndicator = NO;
    _titleView.showsVerticalScrollIndicator = NO;
    _titleView.dataSource = self;
    _titleView.delegate = self;
    _titleView.backgroundColor = [UIColor blueColor];
    [_titleView registerClass:[YCTitleContentViewCell class] forCellWithReuseIdentifier:kReuseCell];
    _titleView.translatesAutoresizingMaskIntoConstraints = NO;
    [self addSubview:_titleView];
    [self addConstraint:[NSLayoutConstraint constraintWithItem:_titleView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeTop multiplier:1 constant:0]];
    [self addConstraint:[NSLayoutConstraint constraintWithItem:_titleView attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeLeading multiplier:1 constant:0]];
    [self addConstraint:[NSLayoutConstraint constraintWithItem:_titleView attribute:NSLayoutAttributeTrailing relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeTrailing multiplier:1 constant:0]];
    _constraintTitleViewHeight = [NSLayoutConstraint constraintWithItem:_titleView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:_tempTitleViewHeight];
    [_titleView addConstraint:_constraintTitleViewHeight];
}

- (void)_buildSelectView {
    if (_selectedView) {
        _selectedView.frame = CGRectMake(0, _tempTitleViewHeight-_tempSelectViewHeight, _tempTitleViewCellWidth, _tempSelectViewHeight);
        [_titleView addSubview:_selectedView];
        [_titleView bringSubviewToFront:_selectedView];
    }
}

- (void)_buildContentView {
    _contentView = [[UIView alloc] init];
    _contentView.translatesAutoresizingMaskIntoConstraints = NO;
    [self addSubview:_contentView];
    [self addConstraint:[NSLayoutConstraint constraintWithItem:_contentView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:_titleView attribute:NSLayoutAttributeBottom multiplier:1 constant:0]];
    [self addConstraint:[NSLayoutConstraint constraintWithItem:_contentView attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeLeading multiplier:1 constant:0]];
    [self addConstraint:[NSLayoutConstraint constraintWithItem:_contentView attribute:NSLayoutAttributeTrailing relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeTrailing multiplier:1 constant:0]];
    [self addConstraint:[NSLayoutConstraint constraintWithItem:_contentView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeBottom multiplier:1 constant:0]];
}

- (void)_updateView {
    if (_dataSource) {
        // 获取设置
        if ([_dataSource respondsToSelector:@selector(numberOfCellsInTitleContentView:)]) {
            _tempNum = [_dataSource numberOfCellsInTitleContentView:self];
        }
        if ([_dataSource respondsToSelector:@selector(heightOfSelectViewInTitleContentView:)]) {
            _tempSelectViewHeight = [_dataSource heightOfSelectViewInTitleContentView:self];
        }
        if ([_dataSource respondsToSelector:@selector(heightOfTitleContentView:)]) {
            _tempTitleViewHeight = [_dataSource heightOfTitleContentView:self];
        }
        if ([_dataSource respondsToSelector:@selector(widthOfCellInTitleContentView:)]) {
            _tempTitleViewCellWidth = [_dataSource widthOfCellInTitleContentView:self];
        }
        // 修改约束，更新视图
        [self _updateSelectView];
        _constraintTitleViewHeight.constant = _tempTitleViewHeight;
        
        [_titleView.collectionViewLayout invalidateLayout];
        [_titleView scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:_selectedIndex inSection:0] atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:YES];
    }
}

- (void)_updateSelectView {
    CGRect rect = _selectedView.frame;
    rect.origin.x = _tempTitleViewCellWidth * _selectedIndex;
    rect.size.width = _tempTitleViewCellWidth;
    _selectedView.frame = rect;
    
    [_titleView bringSubviewToFront:_selectedView];
}

#pragma mark - Setter and Getter

- (void)setDataSource:(id<YCTitleContentViewSource>)dataSource {
    if (_dataSource) {
        _dataSource = dataSource;
    } else {
        _dataSource = dataSource;
        
        // 创建选中效果的指示控件
        if (_selectedView == nil) {
            if ([_dataSource respondsToSelector:@selector(selectViewInTitleContentView:)]) {
                _selectedView = [_dataSource selectViewInTitleContentView:self];
            }
            
            [self _buildSelectView];
        }
        // 显示content
        UIViewController *vc = nil;
        if ([_dataSource respondsToSelector:@selector(titleContentView:contentVCForIndex:)]) {
            vc = [_dataSource titleContentView:self contentVCForIndex:_selectedIndex];
        }
        if (vc) {
            [_viewController addChildViewController:vc];
            _curContentVC = vc;
            
            vc.view.frame = CGRectMake(0, 0, _contentView.bounds.size.width, _contentView.bounds.size.height);
            [vc.view addGestureRecognizer:_panGesture];
            vc.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
            
            [_contentView addSubview:vc.view];
        }
    }
    if (_viewController == nil) {
        _viewController = [self _viewControllerOf:self];
        [_viewController setAutomaticallyAdjustsScrollViewInsets:NO];
    }
    // 更新视图
    [self _updateView];
}

- (void)setSelectedIndex:(NSInteger)selectedIndex {
    _selectedIndex = selectedIndex;
    
    if (_dataSource) {
        if (selectedIndex > -1 && selectedIndex < _tempNum) {
            [self collectionView:_titleView didSelectItemAtIndexPath:[NSIndexPath indexPathForRow:selectedIndex inSection:0]];
        }
    }
}

#pragma mark - UICollectionViewDataSource, UICollectionViewDelegateFlowLayout, UICollectionViewDelegate

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return _tempNum;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    YCTitleContentViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kReuseCell forIndexPath:indexPath];
    cell.titleLabel.text = @"";
    if ([_dataSource respondsToSelector:@selector(titleContentView:cell:atIndex:)]) {
        [_dataSource titleContentView:self cell:cell atIndex:indexPath.row];
    }
    
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == _selectedIndex) {
        [self _updateSelectView];
    }
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    return CGSizeMake(_tempTitleViewCellWidth, _tempTitleViewHeight);
}

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
    return UIEdgeInsetsMake(0, 0, 0, 0);
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout  minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
    return 0;
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
    return 0;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    // 不是之前选中的那个标签
    if (_selectedIndex != indexPath.row) {
        // 保存选择
        _selectedIndex = indexPath.row;
        // 移动选中效果的指示控件
        [self _updateSelectView];
        // 显示选择的标签栏
        [_titleView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:YES];
        // 切换内容
        UIViewController *vc = nil;
        if ([_dataSource respondsToSelector:@selector(titleContentView:contentVCForIndex:)]) {
            vc = [_dataSource titleContentView:self contentVCForIndex:indexPath.row];
        }
        if (vc) {
            [self _switchContentVCToNewController:vc];
        }
    }
}

#pragma mark - UIGestureRecognizerDelegate

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
    CGPoint point = [(UIPanGestureRecognizer *)gestureRecognizer translationInView:gestureRecognizer.view];
    if (point.x > 0) {
        if (_selectedIndex == 0) {
            return YES;
        }
    } else {
        if (_selectedIndex == _tempNum-1) {
            return NO;
        }
    }
    
    return NO;
}

#pragma mark - Gesture Method

- (void)_handlePanGesture:(UIPanGestureRecognizer *)gesture {
    CGPoint point = [gesture translationInView:gesture.view];
    
    if (gesture.state == UIGestureRecognizerStateBegan) {
        _isPaning = YES;
        
        _lastContentVC = nil;
        _nextContentVC = nil;
        if ([_dataSource respondsToSelector:@selector(titleContentView:contentVCForIndex:)]) {
            if (_selectedIndex == 0 && _tempNum > 1) {
                _nextContentVC = [_dataSource titleContentView:self contentVCForIndex:_selectedIndex+1];
            } else if (_selectedIndex == _tempNum-1 && _tempNum > 1) {
                _lastContentVC = [_dataSource titleContentView:self contentVCForIndex:_selectedIndex-1];
            } else if (_selectedIndex > 0 && _selectedIndex < _tempNum-1) {
                _lastContentVC = [_dataSource titleContentView:self contentVCForIndex:_selectedIndex-1];
                _nextContentVC = [_dataSource titleContentView:self contentVCForIndex:_selectedIndex+1];
            }
        }
        
        if (_lastContentVC) {
            [_viewController addChildViewController:_lastContentVC];
            [_lastContentVC didMoveToParentViewController:_viewController];
            
            _lastContentVC.view.frame = CGRectMake(-_contentView.frame.size.width, 0, _contentView.frame.size.width, _contentView.frame.size.height);
            [_contentView addSubview:_lastContentVC.view];
        }
        if (_nextContentVC) {
            [_viewController addChildViewController:_nextContentVC];
            [_nextContentVC didMoveToParentViewController:_viewController];
            
            _nextContentVC.view.frame = CGRectMake(_contentView.frame.size.width, 0, _contentView.frame.size.width, _contentView.frame.size.height);
            [_contentView addSubview:_nextContentVC.view];
        }
    } else if (gesture.state==UIGestureRecognizerStateCancelled || gesture.state==UIGestureRecognizerStateEnded) {
        _isPaning = NO;
        
        if (point.x > 0) {
            if (point.x > _contentView.frame.size.width/2) {
                if (_lastContentVC) {
                    [self _switchContentVCToNewController:_lastContentVC];
                } else {
                    [self _switchContentVCToNewController:_curContentVC];
                }
            } else {
                [self _switchContentVCToNewController:_curContentVC];
            }
        } else {
            if (fabs(point.x) > _contentView.frame.size.width/2) {
                if (_nextContentVC) {
                    [self _switchContentVCToNewController:_nextContentVC];
                } else {
                    [self _switchContentVCToNewController:_curContentVC];
                }
            } else {
                [self _switchContentVCToNewController:_curContentVC];
            }
        }
    } else {
        // 移动选中效果的指示控件
        if ((_lastContentVC && point.x > 0) || (_nextContentVC && point.x < 0)) {
            CGRect rect = _selectedView.frame;
            rect.origin.x = _tempTitleViewCellWidth * _selectedIndex - _tempTitleViewCellWidth * point.x / _contentView.frame.size.width;
            _selectedView.frame = rect;
        }
        // 移动内容
        if ((point.x>0 && _lastContentVC) || (point.x<0 && _nextContentVC)) {
            CGRect curRect = _curContentVC.view.frame;
            curRect.origin.x = point.x;
            _curContentVC.view.frame = curRect;
            
            if (_lastContentVC) {
                CGRect lastRect = _lastContentVC.view.frame;
                lastRect.origin.x = curRect.origin.x - _contentView.frame.size.width;
                _lastContentVC.view.frame = lastRect;
            }
            
            if (_nextContentVC) {
                CGRect nextRect = _nextContentVC.view.frame;
                nextRect.origin.x = curRect.origin.x + _contentView.frame.size.width;
                _nextContentVC.view.frame = nextRect;
            }
        }
    }
}

#pragma mark - Other Method

- (void)_switchContentVCToNewController:(UIViewController *)newController {
    // 手势切换
    if (newController == _curContentVC) {
        // 移动选中效果的指示控件
        [self _updateSelectView];
        // 显示选择的标签栏
        [_titleView scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:_selectedIndex inSection:0] atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:YES];
        // 移动内容
        [UIView animateWithDuration:kDuration animations:^{
            _curContentVC.view.frame = CGRectMake(0, 0, _contentView.frame.size.width, _contentView.frame.size.height);
            if (_lastContentVC) {
                _lastContentVC.view.frame = CGRectMake(-_contentView.frame.size.width, 0, _contentView.frame.size.width, _contentView.frame.size.height);
            }
            if (_nextContentVC) {
                _nextContentVC.view.frame = CGRectMake(_contentView.frame.size.width, 0, _contentView.frame.size.width, _contentView.frame.size.height);
            }
        } completion:^(BOOL finished) {
            if (_lastContentVC) {
                [_lastContentVC.view removeFromSuperview];
                [_lastContentVC removeFromParentViewController];
            }
            if (_nextContentVC) {
                [_nextContentVC.view removeFromSuperview];
                [_nextContentVC removeFromParentViewController];
            }
            
            _lastContentVC = nil;
            _nextContentVC = nil;
        }];
    } else if(newController == _lastContentVC) {
        // 保存选择
        _selectedIndex--;
        // 移动选中效果的指示控件
        [self _updateSelectView];
        // 显示选择的标签栏
        [_titleView scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:_selectedIndex inSection:0] atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:YES];
        // 切换内容
        [UIView animateWithDuration:kDuration animations:^{
            _lastContentVC.view.frame = CGRectMake(0, 0, _contentView.frame.size.width, _contentView.frame.size.height);
            _curContentVC.view.frame = CGRectMake(_contentView.frame.size.width, 0, _contentView.frame.size.width, _contentView.frame.size.height);
        } completion:^(BOOL finished) {
            // 更新标签栏
            [_titleView reloadData];
            // 处理其他视图
            [_curContentVC.view removeFromSuperview];
            [_curContentVC removeFromParentViewController];
            if (_nextContentVC) {
                [_nextContentVC.view removeFromSuperview];
                [_nextContentVC removeFromParentViewController];
            }
            
            _curContentVC = _lastContentVC;
            [_curContentVC.view addGestureRecognizer:_panGesture];
            
            _lastContentVC =  nil;
            _nextContentVC = nil;
        }];
    } else if(newController == _nextContentVC) {
        // 保存选择
        _selectedIndex++;
        // 移动选中效果的指示控件
        [self _updateSelectView];
        // 显示选择的标签栏
        [_titleView scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:_selectedIndex inSection:0] atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:YES];
        // 切换内容
        [UIView animateWithDuration:kDuration animations:^{
            _nextContentVC.view.frame = CGRectMake(0, 0, _contentView.frame.size.width, _contentView.frame.size.height);
            _curContentVC.view.frame = CGRectMake(-_contentView.frame.size.width, 0, _contentView.frame.size.width, _contentView.frame.size.height);
        } completion:^(BOOL finished) {
            // 更新标签栏
            [_titleView reloadData];
            // 处理其他视图
            if (_lastContentVC) {
                [_lastContentVC.view removeFromSuperview];
                [_lastContentVC removeFromParentViewController];
            }
            [_curContentVC.view removeFromSuperview];
            [_curContentVC removeFromParentViewController];
            
            _curContentVC = _nextContentVC;
            [_curContentVC.view addGestureRecognizer:_panGesture];
            
            _nextContentVC = nil;
            _lastContentVC = nil;
        }];
    } else {// 直接切换
        [_titleView reloadData];
        
        [_viewController addChildViewController:newController];
        newController.view.frame = CGRectMake(0, 0, _contentView.frame.size.width, _contentView.frame.size.height);
        [_contentView addSubview:newController.view];
        
        [_curContentVC.view removeFromSuperview];
        [_curContentVC removeFromParentViewController];
        
        _curContentVC = newController;
        [_curContentVC.view addGestureRecognizer:_panGesture];
    }
}

- (UIViewController *)_viewControllerOf:(UIView *)view {
    for (UIView* next = [self superview]; next; next = next.superview) {
        UIResponder* nextResponder = [next nextResponder];
        if ([nextResponder isKindOfClass:[UIViewController class]]) {
            return (UIViewController *)nextResponder;
        }
    }
    return nil;
}

@end

#pragma mark - YCTitleContentViewCell

@implementation YCTitleContentViewCell

- (instancetype)init {
    self =[super init];
    
    [self _configView];
    
    return self;
}

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    
    [self _configView];
    
    return self;
}

- (void)_configView {
    _selectedView = [[UIView alloc] initWithFrame:CGRectMake(0.f, 0.f, 10.f, 10.f)];
    _selectedView.backgroundColor = [UIColor clearColor];
    _selectedView.translatesAutoresizingMaskIntoConstraints = NO;
    [self.contentView addSubview:_selectedView];
    CGFloat height = self.frame.size.height * 0.2;
    CGFloat width = self.frame.size.width * 0.2;
    [self.contentView  addConstraint:[NSLayoutConstraint constraintWithItem:_selectedView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.contentView  attribute:NSLayoutAttributeTop multiplier:1 constant:height]];
    [self.contentView  addConstraint:[NSLayoutConstraint constraintWithItem:_selectedView attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:self.contentView  attribute:NSLayoutAttributeLeading multiplier:1 constant:width]];
    [self.contentView  addConstraint:[NSLayoutConstraint constraintWithItem:_selectedView attribute:NSLayoutAttributeTrailing relatedBy:NSLayoutRelationEqual toItem:self.contentView  attribute:NSLayoutAttributeTrailing multiplier:1 constant:-width]];
    [self.contentView  addConstraint:[NSLayoutConstraint constraintWithItem:_selectedView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.contentView  attribute:NSLayoutAttributeBottom multiplier:1 constant:-height]];
    
    _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.f, 0.f, 10.f, 10.f)];
    _titleLabel.textAlignment = NSTextAlignmentCenter;
    _titleLabel.translatesAutoresizingMaskIntoConstraints = NO;
    [self.contentView addSubview:_titleLabel];
    [self.contentView  addConstraint:[NSLayoutConstraint constraintWithItem:_titleLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.contentView  attribute:NSLayoutAttributeTop multiplier:1 constant:0]];
    [self.contentView  addConstraint:[NSLayoutConstraint constraintWithItem:_titleLabel attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:self.contentView  attribute:NSLayoutAttributeLeading multiplier:1 constant:0]];
    [self.contentView  addConstraint:[NSLayoutConstraint constraintWithItem:_titleLabel attribute:NSLayoutAttributeTrailing relatedBy:NSLayoutRelationEqual toItem:self.contentView  attribute:NSLayoutAttributeTrailing multiplier:1 constant:0]];
    [self.contentView  addConstraint:[NSLayoutConstraint constraintWithItem:_titleLabel attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.contentView  attribute:NSLayoutAttributeBottom multiplier:1 constant:0]];
}

@end
